/**
 * Copyright (C), 2020, 安徽贝慕信息科技有限公司
 * FileName: GateWayRouteConfig
 * Author:   Allen
 * Date:     2020/8/29 9:41
 * Description: 网关服务配置类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bim.marvel.gateway.config;

import com.bim.marvel.gateway.ratelimit.HostKeyResolver;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 〈网关服务配置类〉
 *
 * @author Allen
 * @date 2020/8/29
 * @since 1.0.0
 */
@Configuration
public class GateWayRouteConfig {

    /**
     * 初始化网关
     * @param builder RouteLocatorBuilder
     * @return RouteLocator
     */
    @Qualifier("customerRoutes")
    @Bean
    public RouteLocator customerRoutes(RouteLocatorBuilder builder) {
        return builder.routes().build();
    }

    /**
     * 注入限流的过滤器
     * @return HostKeyResolver
     */
    @Bean
    public HostKeyResolver hostKeyResolver() {
        return new HostKeyResolver();
    }
}
